<?php
namespace Admin\Controller;
/**
 * 品牌控制器
 */
class BrandController extends CommonController {
	protected $db;
	//构造方法
	public function __init() {
		$this -> db = new \Common\Model\Brand;
	}

	/**
	 * 首页
	 */
	public function index() {
		//获取旧数据
		$olddata = $this->db->get();
		//分配数据
		View::with('olddata',$olddata);
		View::make();
	}

	/**
	 * 添加
	 */
	public function store() {
		if (IS_POST) {
			if (!$this -> db -> store()) {
				$this -> error($this -> db -> getError());
			} else {
				$this -> success('添加成功', 'Brand/index');
			}
		}

		View::make();
	}
	/**
	 * 修改
	 */
	public function edit()
	{
		if(IS_POST)
		{
			if(!$this->db->edit())
			{
				$this->error($this->db->getError());
			}else{
				$this->success('成功修改','Brand/index');
			}
		}
		$brand_id = Q('get.brand_id',0,'intval');
		//获取旧数据
		$olddata = $this->db->where('brand_id',$brand_id)->first();
		View::with('olddata',$olddata);
		View::make();
	}
	/**
	 * 删除
	 */
	public function del()
	{
		$brand_id = Q('get.brand_id',0,'intval');
		//执行删除
		$this->db->where('brand_id',$brand_id)->delete();
		$this->success('删除成功','brand/index');
	}
}
